package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferMonthReportFormDao;
import com.tianqu.tms.dto.TransferMonthReportFormDto;

public class TransferMonthReportForm extends TmsEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7007578094722499153L;

	private int id;
	private String carType;// 车辆类型
	private String countryStyle;// 国别
	private String quantity;// 交易量（台）
	private String countPrice;// 总金额（元）
	private int year;// 报表年份
	private int month;// 报表月份
	private int num;
	private int cssFlag;
	private String jquantity;
	private String jcountPrice;

	/**
	 * 月统计
	 * @return
	 * @throws TmsDaoException
	 */
	public List getTransferMonthReportFormInfo(int year, int month)throws TmsDaoException {
		TransferMonthReportFormDao uDao = (TransferMonthReportFormDao) TmsDao
				.getInstance(TmsDao.TMS_TRANSFER_MONTH_REPORTFORM);
		List<TransferMonthReportFormDto> list = uDao.getTransferMonthReportFormInfo(year, month);
		List ll = null;
		if (list.size() > 0) {
			ll = new ArrayList();
			for (int i = 0; i < list.size(); i++) {
				TransferMonthReportFormDto dto = (TransferMonthReportFormDto) list.get(i);
				TransferMonthReportForm entity = new TransferMonthReportForm();
				entity.setCarType(transTool(dto.getCarType()));
				entity.setQuantity(StringUtil.addDH(String.valueOf(dto.getQuantity())));
				entity.setCountPrice(StringUtil.addDH(String.valueOf(dto.getCountPrice())));
				entity.setJquantity(StringUtil.addDH(String.valueOf(dto.getJquantity())));
				entity.setJcountPrice(StringUtil.addDH(String.valueOf(dto.getJcountPrice())));
				entity.setNum(i + 1);
				if (i % 2 == 0) {
					entity.setCssFlag(0);
				} else {
					entity.setCssFlag(1);
				}
				ll.add(entity);
			}
		}
		return ll;
	}
	/**
	 * 年统计
	 * @return
	 * @throws TmsDaoException
	 */
	public List getTransferYearReportFormInfo(int year)throws TmsDaoException {
		TransferMonthReportFormDao uDao = (TransferMonthReportFormDao) TmsDao
				.getInstance(TmsDao.TMS_TRANSFER_MONTH_REPORTFORM);
		List<TransferMonthReportFormDto> list = uDao.getTransferYearReportFormInfo(year);
		List ll = null;
		if (list.size() > 0) {
			ll = new ArrayList();
			int quantity1 = 0;// 交易量（台）
			int countPrice1 = 0;// 总金额（元）
			int jquantity1 = 0;
			int jcountPrice1 = 0;
			
			int quantity2 = 0;// 交易量（台）
			int countPrice2 = 0;// 总金额（元）
			int jquantity2 = 0;
			int jcountPrice2 = 0;
			
			int quantity3 = 0;// 交易量（台）
			int countPrice3 = 0;// 总金额（元）
			int jquantity3 = 0;
			int jcountPrice3 = 0;
			
			int quantity4 = 0;// 交易量（台）
			int countPrice4 = 0;// 总金额（元）
			int jquantity4 = 0;
			int jcountPrice4 = 0;
			
			int quantity5 = 0;// 交易量（台）
			int countPrice5 = 0;// 总金额（元）
			int jquantity5 = 0;
			int jcountPrice5 = 0;
			
			int quantity6 = 0;// 交易量（台）
			int countPrice6 = 0;// 总金额（元）
			int jquantity6 = 0;
			int jcountPrice6 = 0;
			for (int i = 0; i < list.size(); i++) {
				TransferMonthReportFormDto dto = (TransferMonthReportFormDto) list.get(i);
				if(dto.getCarType() == 1)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity1 =quantity1+dto.getQuantity();
						countPrice1 = countPrice1 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity1 = jquantity1 + dto.getQuantity();
						jcountPrice1 = jcountPrice1 + dto.getCountPrice();
					}
				}
				if(dto.getCarType() == 2)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity2 =quantity2+dto.getQuantity();
						countPrice2 = countPrice2 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity2 = jquantity2 + dto.getQuantity();
						jcountPrice2 = jcountPrice2 + dto.getCountPrice();
					}
				}
				if(dto.getCarType() == 3)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity3 =quantity3+dto.getQuantity();
						countPrice3 = countPrice3 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity3 = jquantity3 + dto.getQuantity();
						jcountPrice3 = jcountPrice3 + dto.getCountPrice();
					}
				}
				if(dto.getCarType() == 4)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity4 =quantity4+dto.getQuantity();
						countPrice4 = countPrice4 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity4 = jquantity4 + dto.getQuantity();
						jcountPrice4 = jcountPrice4 + dto.getCountPrice();
					}
				}
				if(dto.getCarType() == 5)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity5 =quantity5+dto.getQuantity();
						countPrice5 = countPrice5 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity5 = jquantity5 + dto.getQuantity();
						jcountPrice5 = jcountPrice5 + dto.getCountPrice();
					}
				}
				if(dto.getCarType() == 6)
				{
					if(dto.getCountryStyle() == 0)
					{
						quantity6 =quantity6+dto.getQuantity();
						countPrice6 = countPrice6 + dto.getCountPrice();
					}
					if(dto.getCountryStyle() == 1)
					{
						jquantity6 = jquantity6 + dto.getQuantity();
						jcountPrice6 = jcountPrice6 + dto.getCountPrice();
					}
				}
			}
			TransferMonthReportForm entity = new TransferMonthReportForm();
			entity.setCarType(transTool(1));
			entity.setQuantity(StringUtil.addDH(String.valueOf(quantity1)));
			entity.setCountPrice(StringUtil.addDH(String.valueOf(countPrice1)));
			entity.setJquantity(StringUtil.addDH(String.valueOf(jquantity1)));
			entity.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice1)));
			entity.setNum(1);
			entity.setCssFlag(0);
			ll.add(entity);
			
			TransferMonthReportForm entity1 = new TransferMonthReportForm();
			entity1.setCarType(transTool(2));
			entity1.setQuantity(StringUtil.addDH(String.valueOf(quantity2)));
			entity1.setCountPrice(StringUtil.addDH(String.valueOf(countPrice2)));
			entity1.setJquantity(StringUtil.addDH(String.valueOf(jquantity2)));
			entity1.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice2)));
			entity1.setNum(2);
			entity1.setCssFlag(1);
			ll.add(entity1);
			
			TransferMonthReportForm entity2 = new TransferMonthReportForm();
			entity2.setCarType(transTool(3));
			entity2.setQuantity(StringUtil.addDH(String.valueOf(quantity3)));
			entity2.setCountPrice(StringUtil.addDH(String.valueOf(countPrice3)));
			entity2.setJquantity(StringUtil.addDH(String.valueOf(jquantity3)));
			entity2.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice3)));
			entity2.setNum(3);
			entity2.setCssFlag(0);
			ll.add(entity2);
			
			TransferMonthReportForm entity3 = new TransferMonthReportForm();
			entity3.setCarType(transTool(4));
			entity3.setQuantity(StringUtil.addDH(String.valueOf(quantity4)));
			entity3.setCountPrice(StringUtil.addDH(String.valueOf(countPrice4)));
			entity3.setJquantity(StringUtil.addDH(String.valueOf(jquantity4)));
			entity3.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice4)));
			entity3.setNum(4);
			entity3.setCssFlag(1);
			ll.add(entity3);
			
			TransferMonthReportForm entity4 = new TransferMonthReportForm();
			entity4.setCarType(transTool(5));
			entity4.setQuantity(StringUtil.addDH(String.valueOf(quantity5)));
			entity4.setCountPrice(StringUtil.addDH(String.valueOf(countPrice5)));
			entity4.setJquantity(StringUtil.addDH(String.valueOf(jquantity5)));
			entity4.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice5)));
			entity4.setNum(5);
			entity4.setCssFlag(0);
			ll.add(entity4);
			
			TransferMonthReportForm entity5 = new TransferMonthReportForm();
			entity5.setCarType(transTool(6));
			entity5.setQuantity(StringUtil.addDH(String.valueOf(quantity6)));
			entity5.setCountPrice(StringUtil.addDH(String.valueOf(countPrice6)));
			entity5.setJquantity(StringUtil.addDH(String.valueOf(jquantity6)));
			entity5.setJcountPrice(StringUtil.addDH(String.valueOf(jcountPrice6)));
			entity5.setNum(6);
			entity5.setCssFlag(1);
			ll.add(entity5);
		}
		return ll;
	}
	public TransferMonthReportForm getTotleInfo(int year,int month,int countryStyle) throws TmsDaoException
	{
		TransferMonthReportFormDao uDao = (TransferMonthReportFormDao) TmsDao
		.getInstance(TmsDao.TMS_TRANSFER_MONTH_REPORTFORM);
		TransferMonthReportFormDto dto = uDao.getTotleInfo(year,month,countryStyle);
		TransferMonthReportForm entity = null;
		if(dto!=null)
		{
			entity = new TransferMonthReportForm();
			entity.setQuantity(StringUtil.addDH(String.valueOf(dto.getQuantity())));
			entity.setCountPrice(StringUtil.addDH(String.valueOf(dto.getCountPrice())));
		}
		return entity;
	}

	private String transTool(int i) {
		switch (i) {
		case 1:
			return "轿车";
		case 2:
			return "越野车";
		case 3:
			return "面包车";
		case 4:
			return "客车";
		case 5:
			return "货车";
		case 6:
			return "特种车";
		default:
			return "";
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCarType() {
		return carType;
	}

	public void setCarType(String carType) {
		this.carType = carType;
	}

	public String getCountryStyle() {
		return countryStyle;
	}

	public void setCountryStyle(String countryStyle) {
		this.countryStyle = countryStyle;
	}

	public String getQuantity() {
		return quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	public String getCountPrice() {
		return countPrice;
	}

	public void setCountPrice(String countPrice) {
		this.countPrice = countPrice;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getCssFlag() {
		return cssFlag;
	}

	public void setCssFlag(int cssFlag) {
		this.cssFlag = cssFlag;
	}

	public String getJquantity() {
		return jquantity;
	}
	public void setJquantity(String jquantity) {
		this.jquantity = jquantity;
	}
	public String getJcountPrice() {
		return jcountPrice;
	}
	public void setJcountPrice(String jcountPrice) {
		this.jcountPrice = jcountPrice;
	}
	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub

	}

}
